<template>
	<view>
		<button type="primary" :style="{margin:'20px'}" @click="txsdk">腾讯sdk</button>
		<button type="primary" :style="{margin:'20px'}" @click="agorasdk">声网sdk</button>
		<button type="primary" :style="{margin:'20px'}" @click="tim">腾讯IM</button>
	</view>
</template>

<script>
    import RouteUtil from "../../utils/js/route-util";
    import {setTokenStorage} from "../../utils/token";
    import TIM from "tim-js-sdk";
    import Http from "../../utils/http";

    export default {
        name: "sdk",
        methods: {
            tim() {
                //RouteUtil.forward(RouteUtil.TIM)
                this.loginTxIM()
            },
            txsdk() {
                RouteUtil.forward(RouteUtil.LIVE_TX_SDK)
            },
            agorasdk() {
                RouteUtil.forward(RouteUtil.LIVE_AGORA_SDK)
            },


            /**
             * 自己写的方法，登录腾讯IM
             */
            loginTxIM() {
                const user = uni.getStorageSync('user')
                console.log("腾讯IM:", "开始登录user:", user)


                uni.$TUIKit.on(TIM.EVENT.SDK_READY, data => {
                    console.log("腾讯IM:", 'onSDKReady----->', data)
                    if (data.name === uni.$TUIKitEvent.SDK_READY) {
                        RouteUtil.forward(RouteUtil.TIM)
                    }

                });


                uni.$TUIKit.login({userID: user.id, userSig: user.usersig})
                    .then(function (imResponse) {
                        console.log("腾讯IM:", "登录成功", imResponse.data); // 登录成功
                        if (imResponse.data.repeatLogin === true) {
                            // 标识帐号已登录，本次登录操作为重复登录。v2.5.1 起支持
                            console.log("腾讯IM:", "重复登录", imResponse.data.errorInfo);
                        }
                        //
                        // app.globalData.userInfo = {
                        //     userSig:user.usersig,
                        //     userID:user.id
                        // };
                        // setTokenStorage({
                        //     userInfo: app.globalData.userInfo
                        // });


                    })
                    .catch(function (imError) {
                        console.warn("腾讯IM:", '登录失败 login error:', imError); // 登录失败的相关信息
                    });
            }
        },

        mounted() {


        }

    }
</script>

<style scoped>

</style>
